﻿/******************************************************************
** 文 件 名: Bu_AuditTable_FGWDetail_DAL.cs
** Copyright (c) 2010-2012 Honestysoft (GuangZhou) Co.,LTD
** 创 建 人: 此代码由生成器自动生成
** 创建日期: 2013/3/1 17:19:35
** 描    述: 实现公共部分的数据访问封装，提供资金支付汇总表-发改委返回-明细的数据访问类
** 版    本: 2.0.0.0
** 修改描述:
** 修 改 人:
** 修改日期:
******************************************************************/
using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Text;
using Honestysoft.BaseObject;
using Honestysoft.Financing.Model;

namespace Honestysoft.Financing.DataAccess
{
	/// <summary>
    /// Bu_AuditTable_FGWDetail数据访问类
    /// </summary>
	public partial class Bu_AuditTable_FGWDetail_DAL : BaseDataAccess<Bu_AuditTable_FGWDetail>
    {		
		/// <summary>
        /// 构造函数，使用指定的连接字符串
        /// </summary>
        /// <param name="connectionStringName">连接字符串名称</param>
        public Bu_AuditTable_FGWDetail_DAL(string connectionStringName)
            : base(connectionStringName)
        {

        }
        /// <summary>
        /// 得到同批次不同支付次数的其他汇总表的明细记录数
        /// </summary>
        /// <param name="batchID"></param>
        /// <param name="thisCounter"></param>
        /// <returns></returns>
        public int GetOtherCounterCount(string batchID, int thisCounter)
        { 
            DbParameter pBatchID=CreateParameter("BatchID");
            pBatchID.DbType = DbType.String;
            pBatchID.Value = batchID;
            DbParameter pCounter=CreateParameter("Counter");
            pCounter.DbType = DbType.Int32;
            pCounter.Value = thisCounter;
            string sql = string.Format(@"Select Count(ATID) From Bu_AuditTable_FGWDetail
                Where FGWID in
                (Select ID From Bu_AuditTable_FGW Where BatchID={0} And Counter <> {1})", pBatchID.ParameterName, pCounter.ParameterName);
            DbCommand command = GetDbCommand(sql);
            command.Parameters.Add(pBatchID);
            command.Parameters.Add(pCounter);
            object obj = ExecuteScalar(command);
            if (obj == null || obj == DBNull.Value)
            {
                return 0;
            }
            return Convert.ToInt32(obj);
        }

        /// <summary>
        /// 得到同批次不同支付次数的其他汇总表的明细记录
        /// </summary>
        /// <param name="batchID"></param>
        /// <param name="thisCounter"></param>
        /// <returns></returns>
        public DataTable GetOtherCounterAT(string batchID, int thisCounter)
        {
            DbParameter pBatchID = CreateParameter("BatchID");
            pBatchID.DbType = DbType.String;
            pBatchID.Value = batchID;
            DbParameter pCounter = CreateParameter("Counter");
            pCounter.DbType = DbType.Int32;
            pCounter.Value = thisCounter;
            string sql = string.Format(@"Select * From Bu_AuditTable_FGWDetail
Where FGWID
Not In (Select ID From Bu_AuditTable_FGW Where BatchID={0} And Counter={1})", pBatchID.ParameterName, pCounter.ParameterName);
            DbCommand command = GetDbCommand(sql);
            command.Parameters.Add(pBatchID);
            command.Parameters.Add(pCounter);
            return ExecuteDataTable(command);
        }
    }
}
